package com.bjshiwei.zhengu.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
 * 作者：Administrator on 2016/9/28 0028 17:08
 * 邮箱：sanjins@126.com
 */


public class DateFormatUtil {
    private static DateFormatUtil dateFormatUtil = null;
    public static final int timeLine = 86400000;
    private SimpleDateFormat simpleDateFormat;
    private String formatTime;

    private DateFormatUtil(){}
    public synchronized static DateFormatUtil getInstance(){
        if(null==dateFormatUtil) {
            dateFormatUtil = new DateFormatUtil();
        }
        System.setProperty("user.timezone", "Asia/Shanghai");
        TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
        TimeZone.setDefault(tz);
        return dateFormatUtil;
    }

    //转换成24小时
    public String dateFromatToHour(long time){
        Date date = new Date(time*1000L);
        long current = System.currentTimeMillis();
        Date currentDate = new Date(current);
        SimpleDateFormat simple = new SimpleDateFormat("MMdd");
        String formatDate = simple.format(date);
        String formatCurrentDate = simple.format(currentDate);
        if(formatCurrentDate.equals(formatDate)) {
            simpleDateFormat = new SimpleDateFormat("HH:mm");
        }else{
            simpleDateFormat = new SimpleDateFormat("MM-dd");
        }
        formatTime = simpleDateFormat.format(date);
        return formatTime;
    }

//转换成24小时
    public String dateFromatToHour2(long time){
        Date date = new Date(time);
        long current = System.currentTimeMillis();
        Date currentDate = new Date(current);
        SimpleDateFormat simple = new SimpleDateFormat("MMdd");
        String formatDate = simple.format(date);
        String formatCurrentDate = simple.format(currentDate);
        if(formatCurrentDate.equals(formatDate)) {
            simpleDateFormat = new SimpleDateFormat("HH:mm");
        }else{
            simpleDateFormat = new SimpleDateFormat("MM-dd");
        }
        formatTime = simpleDateFormat.format(date);
        return formatTime;
    }




    public String dateFormatLive(long time){
        Date date = new Date(time);
        simpleDateFormat = new SimpleDateFormat("yyyyddMMHHssmm");
        return simpleDateFormat.format(date);
    }


}
